#include<iostream>
#include<algorithm>
using namespace std;
typedef struct student
{
	int id;
	char name[105];
	int score[4];
	int sum = 0;
}stu;
stu s[105];
bool cmp(stu a, stu b)
{
	if (a.sum != b.sum)
	{
		return a.sum < b.sum;
	}
	return strcmp(a.name, b.name) < 0;
}
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> s[i].name;
		for (int j = 0; j < 4; j++)
		{
			cin >> s[i].score[i];
			s[i].sum += s[i].score[i];
		}
	}
	sort(s, s + n,cmp);
	return 0;
}